package com.ssm.studen.controller;

import com.ssm.studen.model.Examquestiontype;
import com.ssm.studen.service.ExamquestiontypeService;
import com.ssm.studen.tool.ResponseMessage;
import com.ssm.studen.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 考题类型：
 *      对外提供数据服务接口
 */
@Api(tags = "examquestiontype")
@RestController
public class ExamquestiontypeController {

    @Autowired
    private ExamquestiontypeService examquestiontypeService;


    /*******************考题类型查询*********************/
    @ApiOperation("考题类型查询")
    @RequestMapping(value = "/selectExamquestionType",method = RequestMethod.PUT)
    public int selectExamquestionType(int eqtnum){
        return examquestiontypeService.selectExamquestionType(eqtnum);
    }


    /*******************考题类型表添加*********************/
    @ApiOperation("考题类型表添加")
    @RequestMapping(value = "/insertExamquestionType",method = RequestMethod.GET)
    public ResponseMessage insertExamquestionType(Examquestiontype examquestiontype){
        int IsAdd = 0;
        //传入数据判断
        //1.实体对象不能为空
        if(examquestiontype != null){
            //2.不能为空
            if(examquestiontype.getEqtnum()!=0&&
                    examquestiontype.getEqtname()!=null&&
                    examquestiontype.getEqtbz()!=null&&
                    examquestiontype.getEqtfather()!=0){
                //3.添加数据
                IsAdd = examquestiontypeService.insertExamquestionType(examquestiontype);
                if(IsAdd == 1){
                    return Result.success("保存成功");
                }else if(IsAdd == -1){
                    return Result.error("重复不允许添加！");
                }else{
                    return Result.error("保存失败");
                }
            }
        }
        return Result.error("保存失败");
    }


    /*************************考题类型更新方法****************************/
    @ApiOperation("考题类型更新方法")
    @RequestMapping(value = "/updateExamquestionType",method = RequestMethod.GET)
    public ResponseMessage updateExamquestionType(Examquestiontype examquestiontype){
        //传入的参数不能为空
        if(examquestiontype != null){
            //参数当中主键不能为0
            if(examquestiontype.getEqtnum() != 0){
                if(examquestiontypeService.updateExamquestionType(examquestiontype) == 1){
                    if(examquestiontype.getEqtnum()!=0&&
                            examquestiontype.getEqtname()!=null&&
                            examquestiontype.getEqtbz()!=null&&
                            examquestiontype.getEqtfather()!=0){
                       examquestiontypeService.updateExamquestionType(examquestiontype);
                    }
                    return Result.success("更新成功");
                }else{
                    return Result.error("更新失败");
                }
            }
        }
        return Result.error("传入参数不正确");
    }
}















